<template>
	<view v-if="info==''">
		<xbd-zwnz marginTop='300'></xbd-zwnz>
	</view>
	<view v-else class="center">
		<xbd-page-card>
			<template>
				<view class="box">
					<image v-if="info.is_templete" class="imgs" src="@/static/image/templa.png"></image>
					<xbd-image-title :title="info.item" :image="require('@/static/image/supervision/jdh.png')">
					</xbd-image-title>
					<view class="tag">
						风险等级
					</view>
					<view class="text">
						<text :style="{ color: gradeColor(info.level) }">
							{{info.level}}</text>
					</view>
					<view class="tag">
						预警对象
					</view>
					<view class="text">
						<text v-for="(item,index) in info.target_name" :key="index" class="name">{{item.name}}</text>
					</view>
					<view class="tag">
						预警事项
					</view>
					<view class="text">
						{{info.item}}
					</view>
					<view class="tag">
						预警意见
					</view>
					<view class="text">
						{{info.view}}
					</view>
					<view class="tag">
						防控措施
					</view>
					<view class="text">
						{{info.measures}}
					</view>
					<view class="tag">
						预警时间
					</view>
					<view class="text">
						{{info.time | timeFormat('YYYY-MM-DD HH:mm')}}
					</view>
					<view class="tag">
						提交人
					</view>
					<view class="text">
						{{info.submit_person}}
					</view>
					<view class="tag">
						提交时间
					</view>
					<view class="text">
						{{info.submit_time | timeFormat('YYYY-MM-DD HH:mm')}}
					</view>

				</view>
			</template>
		</xbd-page-card>

		<!-- 已审批 查看 -->
		<xbd-page-card>
			<template>
				<view class="center_box">
					<image v-if="info.audit_state === 'refused'" class="img"
						src="@/static/image/supervision/refused.png"></image>
					<image v-if="info.audit_state === 'successed'" class="img"
						src="@/static/image/supervision/pass.png"></image>
					<view class="tag">
						审核人
					</view>
					<view v-if="info.audit_person" class="text">
						{{info.audit_person}}
					</view>
					<view v-else class="text">
						{{userInfo.name}}
					</view>
					<view class="tag">
						审核意见
					</view>
					<view v-if="info.audit_state !== 'wait'" class="text">
						{{info.audit_view||'-'}}
					</view>
					<textarea v-else class="textarea" placeholder="请输入内容..." v-model="o.audit_view" maxlength="-1"
						auto-height></textarea>
					<view v-if="info.audit_state !=='wait'" class="tag">
						审核时间
					</view>
					<view v-if="info.audit_state !=='wait'" class="text">
						{{info.audit_time | timeFormat('YYYY-MM-DD HH:mm')}}
					</view>
					<view v-if="info.audit_state === 'wait'" class="prompt">
						注：1.预警提交审核通过后，系统会在预警时间当日08:00自动向预警对象发送页面内的预警内容。<br>
						2.模板提交审核通过后，系统会每年在预警时间当日08:00自动向预警对象发送页面内的预警内容，再次发送无需审核。
					</view>
				</view>
			</template>
		</xbd-page-card>
		<xbd-popup :isShow="showDialog" @dialogConfirm="dialogConfirm" @dialogCancel="dialogCancel" :content="msg"
			cancelText="取消" confirmText="确定"></xbd-popup>
		<view class=" floot" v-if="info.audit_state ==='wait'">
			<view class="btn refused" @click="click('refused')">
				拒绝
			</view>
			<view class="btn pass" @click="click('successed')">
				通过
			</view>
		</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		Prevention
	} from '@/api/index.js';
	export default {
		data() {
			return {
				// value: "",
				id: '',
				showDialog: false,
				flag: true,
				info: '',
				msg: '',
				style: {
					'img': 'display:block;margin: 0 auto;max-width:100%;height:auto; transform: translateX(0);',
					'video': 'width:100%;height:auto;',
				},
				o: {
					id: '',
					audit_view: '',
					audit_state: ''
				}
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			gradeColor(val) {
				let res = "";
				switch (val) {
					case "低":
						res = "#2E73FC";
						break;
					case "中":
						res = "orange";
						break;
					case "高":
						res = "red";
						break;
				}
				return res;
			},
			click(val) {
				if (val === 'refused') {
					this.o.audit_state = 'refused'
					this.msg = '确定审核拒绝？'
				} else {
					this.o.audit_state = 'successed'
					this.msg = '确定审核通过？'
				}
				this.showDialog = true
			},
			dialogConfirm() {
				console.log('确认')
				this.flag = false
				this.Audit()
				this.showDialog = false
			},
			dialogCancel() {
				this.showDialog = false
			},
			async Audit() {
				const res = await Prevention.postRiskAudit(this.o)
				if (!res.success) {
					this.flag = true
					this.$showToast(res.msg);
				} else {
					this.$showToast(res.msg);
					setTimeout(() => {
						// 这里添加您的逻辑		
						uni.navigateBack({
							delta: 1
						});
					}, 1500)


				}
				console.log(res, 'res')
			},
			async init() {
				const res = await Prevention.getWarnDetail(this.id)
				if (!res.success) {
					this.$showToast(res.msg);
				} else {
					this.info = res.data
				}
				console.log(this.info, 'this.info')
			}
		},
		async onLoad(res) {
			this.id = res.id
			this.o.id = res.id
			console.log(res)
			await this.init()
		}
	}
</script>

<style lang="scss" scoped>
	.center {

		padding: 32rpx;
		font-size: 30rpx;
		line-height: 52rpx;

		.box {
			position: relative;

			.imgs {
				width: 92rpx;
				height: 44rpx;
				position: absolute;
				top: -32rpx;
				right: -32rpx;
			}
		}

		.center_box {
			position: relative;

			.img {
				position: absolute;
				right: 30rpx;
				top: 40rpx;
				width: 100rpx !important;
				height: 100rpx !important;

			}
		}

		.prompt {
			font-size: 24rpx;
			font-weight: 400;
			color: #a0a7b8;
			line-height: 40rpx;
		}

		.tag {
			color: #A0A7B8;
			font-size: 26rpx;

			// margin-bottom: 20rpx;

		}

		.text {
			margin-bottom: 20rpx;
			white-space: pre-line !important;
			word-break: break-all !important;
			word-wrap: break-word;

			.name {
				margin-right: 20rpx;
			}

			.text-color {
				margin-left: 20rpx;
				padding: 3rpx 6rpx;
				background: rgba(252, 185, 79, 0.15);
				border-radius: 4rpx;
				color: #FCB94F;
			}
		}

		.textarea {
			min-height: 160rpx;
			padding: 20rpx 30rpx;
			font-size: 30rpx;
			border: 2rpx solid #EBEEF5;
			margin-bottom: 20rpx;
			border-radius: 8rpx;
		}

		.floot {
			margin-top: 60rpx;
			display: flex;
			justify-content: space-between;

			.btn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 316rpx;
				height: 90rpx;
				font-size: 32rpx;
				border-radius: 8rpx;
			}

			.refused {
				border: 2rpx solid #2e73fc;
				color: #2e73fc;
			}

			.pass {
				background: linear-gradient(266deg, #2e73fc 3%, #1ea9fb 95%);
				color: #FFFFFF;
			}
		}
	}
</style>
